﻿using HC.Standard.UniversalAudioScheme;
using HC.Standard.UniversalAudioScheme.Models;
using InnerAudioScheme.Models;
using Microsoft.VisualBasic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NPOI.POIFS.Properties;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace InnerAudioScheme.PopupWindows
{
    /// <summary>
    /// ConfigWindow.xaml 的交互逻辑
    /// </summary>
    public partial class ConfigWindow : Window,INotifyPropertyChanged
    {
        private DataTable? _dataTable = null;


        public ObservableCollection<String> audioTypeColletion { get; set; } = new ObservableCollection<String>();
        public ObservableCollection<String> audioGroupColletion { get; set; } = new ObservableCollection<String>();
        public ObservableCollection<int> audioHzColletion { get; set; } = new ObservableCollection<int>();


        //   public NotifyAudioCombination _audioCombination { get; set; }

        private NotifyAudioCombination _audioCombination;

        public NotifyAudioCombination _AudioCombination
        {
            get => _audioCombination;
            set
            {
                if (_audioCombination != value)
                {
                    _audioCombination = value;
                    OnPropertyChanged(nameof(_AudioCombination));
                }
            }
        }


        private string _selectedItem;
        public string SelectedItem
        {
            get { return _selectedItem; }
            set
            {
                _selectedItem = value;
                OnPropertyChanged(nameof(SelectedItem));
            }
        }


        private NotifyAudioCombination _currentCombination;

        public NotifyAudioCombination CurrentCombination
        {
            get => _currentCombination;
            set
            {
                if (_currentCombination != value)
                {
                    _currentCombination = value;
                    OnPropertyChanged(nameof(CurrentCombination));
                }
            }
        }

        //  private NotifyAudioCombination _audioCombination = null;

        private AudioCombination _parentScheme = new AudioCombination();

     //   private AudioCombination? curruentAudioCombination = null;

        public NotifyAudioCombination curruentAudioCombination { get; set; }

     

      //  private AudioCombination? _selectAudioCombination = null;


        private NotifyAudioCombination? _selectAudioCombination = null;

        public ObservableCollection<NotifyAudioCombination> AudioCombinationColletion { get; set; } = new ObservableCollection<NotifyAudioCombination>();



        public string strFileContent = string.Empty;

        public  List<AudioInfo> _allAudio = new List<AudioInfo>();
        private bool _isLoaded;

        public event PropertyChangedEventHandler? PropertyChanged;

        private List<string> tempAudioTypes = new List<string>();


        protected virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

        public ConfigWindow()
        {
            InitializeComponent();
            this.DataContext = this;
            this.Loaded += ConfigWindow_Loaded;
           
            //tempAudioTypes = _allAudio.Where(a => a.audio_type)


        }

        private void ConfigWindow_Loaded(object sender, RoutedEventArgs e)
        {
            //throw new NotImplementedException();
            _isLoaded = true;

            IEnumerable<string> distinctNames = _allAudio.Select(obj => obj.audio_type).Distinct();

            audioTypeColletion.Clear();
            foreach (var item in distinctNames)
            {
                audioTypeColletion.Add(item);
            }

            if (strFileContent != string.Empty)
            {              
                _AudioCombination = JsonConvert.DeserializeObject<NotifyAudioCombination>(strFileContent);
                               
                if (_AudioCombination != null)
                {
                   
                    AudioCombinationColletion.Add(_AudioCombination);
                }
                
            }
            else
            {
              
                _AudioCombination =  new NotifyAudioCombination() { time = new HC.Standard.UniversalAudioScheme.TimeConfiguration(),};

                if (_AudioCombination.time==null)
                {
                    _AudioCombination.time = new HC.Standard.UniversalAudioScheme.TimeConfiguration();
                }
                _AudioCombination.time.minPercent = 1;
                this.byTime.IsEnabled = false;
                this.byCount.IsEnabled = false;
                this.byFill.IsEnabled = false;

                CurrentCombination = _AudioCombination;
                AudioCombinationColletion.Add(_AudioCombination);
            }
          

        }

        private void btnReturn_Click(object sender, RoutedEventArgs e)
        {
            //_audioCombination= JsonConvert.DeserializeObject<AudioCombination>(strFileContent);
            //_rootSchemeTree = new SchemeTree { Name = _audioCombination.name, audioCombination = _audioCombination };
            //AddTree(_rootSchemeTree, _audioCombination);
            //treeView.ItemsSource = new List<SchemeTree> { _rootSchemeTree };
            this.Close();
        }
      

        private void treeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
        {
       

          //  var parent = selectedItem2.Parent as TreeViewItem;


            // 获取选中项
            NotifyAudioCombination selectedItem = treeView.SelectedItem as NotifyAudioCombination;
            if (selectedItem != null)
            {             

             //   curruentAudioCombination=selectedItem;
                CurrentCombination = selectedItem;
               


                if (CurrentCombination.combinations != null&& CurrentCombination.combinations.Count > 0)
                {
                    this.configAudioInfo.IsChecked = false;
                }

                if (CurrentCombination.information == null)
                {
                    this.configAudioInfo.IsChecked = false;
                }

                if (CurrentCombination.time == null && CurrentCombination.count != 0)
                {
                    //选择三个Radio其中之一

                    this.byCount.IsChecked = true;

                    if (CurrentCombination.combinations != null && CurrentCombination.combinations.Count > 0)
                    {
                        this.configAudioInfo.IsChecked = false;
                    }
                    else if (CurrentCombination.information != null)
                    {
                        this.configAudioInfo.IsChecked = true;

                        switch (CurrentCombination.information.audioHz.selectionType)
                        {
                            case Models.AudioSelectionType.Equal:
                                condition3_ComboBox.SelectedIndex = 0;
                                break;
                            case Models.AudioSelectionType.NotEqual:
                                condition3_ComboBox.SelectedIndex = 1;
                                break;
                            case Models.AudioSelectionType.Contains:
                                condition3_ComboBox.SelectedIndex = 2;
                                break;
                            case Models.AudioSelectionType.NotContains:
                                condition3_ComboBox.SelectedIndex = 3;
                                break;
                            default:
                                condition3_ComboBox.SelectedIndex = -1;
                                break;
                        }

                        switch (CurrentCombination.information.audioType.selectionType)
                        {
                            case Models.AudioSelectionType.Equal:
                                condition_ComboBox.SelectedIndex = 0;
                                break;
                            case Models.AudioSelectionType.NotEqual:
                                condition_ComboBox.SelectedIndex = 1;
                                break;
                            case Models.AudioSelectionType.Contains:
                                condition_ComboBox.SelectedIndex = 2;
                                break;
                            case Models.AudioSelectionType.NotContains:
                                condition_ComboBox.SelectedIndex = 3;
                                break;
                            default:
                                condition_ComboBox.SelectedIndex = -1;
                                break;
                        }

                        switch (CurrentCombination.information.audioGroup.selectionType)
                        {
                            case Models.AudioSelectionType.Equal:
                                condition2_ComboBox.SelectedIndex = 0;
                                break;
                            case Models.AudioSelectionType.NotEqual:
                                condition2_ComboBox.SelectedIndex = 1;
                                break;
                            case Models.AudioSelectionType.Contains:
                                condition2_ComboBox.SelectedIndex = 2;
                                break;
                            case Models.AudioSelectionType.NotContains:
                                condition2_ComboBox.SelectedIndex = 3;
                                break;
                            default:
                                condition2_ComboBox.SelectedIndex = -1;
                                break;
                        }
                        //string aStr = (condition3_ComboBox.SelectedItem as ComboBoxItem).Content.ToString();
                        //if (aStr == "等于")
                        //{
                        //    CurrentCombination.information.audioHz.selectionType = InnerAudioScheme.Models.AudioSelectionType.Equal;
                        //}
                        //else if (aStr == "不等于")
                        //{
                        //    CurrentCombination.information.audioHz.selectionType = InnerAudioScheme.Models.AudioSelectionType.NotEqual;
                        //}
                        //else if (aStr == "包含")
                        //{
                        //    CurrentCombination.information.audioHz.selectionType = InnerAudioScheme.Models.AudioSelectionType.Contains;
                        //}
                        //else
                        //{
                        //    CurrentCombination.information.audioHz.selectionType = InnerAudioScheme.Models.AudioSelectionType.NotContains;
                        //}




                    }
                    else
                    {

                    }

                }
                else if (CurrentCombination.time == null && CurrentCombination.count == 0)
                {
                    this.byFill.IsChecked = true;

                    if (CurrentCombination.combinations != null && CurrentCombination.combinations.Count > 0)
                    {
                        this.configAudioInfo.IsChecked = false;
                    }
                    else if (CurrentCombination.information != null)
                    {
                        this.configAudioInfo.IsChecked = true;


                        switch (CurrentCombination.information.audioHz.selectionType)
                        {
                            case Models.AudioSelectionType.Equal:
                                condition3_ComboBox.SelectedIndex = 0;
                                break;
                            case Models.AudioSelectionType.NotEqual:
                                condition3_ComboBox.SelectedIndex = 1;
                                break;
                            case Models.AudioSelectionType.Contains:
                                condition3_ComboBox.SelectedIndex = 2;
                                break;
                            case Models.AudioSelectionType.NotContains:
                                condition3_ComboBox.SelectedIndex = 3;
                                break;
                            default:
                                condition3_ComboBox.SelectedIndex = -1;
                                break;
                        }

                        switch (CurrentCombination.information.audioType.selectionType)
                        {
                            case Models.AudioSelectionType.Equal:
                                condition_ComboBox.SelectedIndex = 0;
                                break;
                            case Models.AudioSelectionType.NotEqual:
                                condition_ComboBox.SelectedIndex = 1;
                                break;
                            case Models.AudioSelectionType.Contains:
                                condition_ComboBox.SelectedIndex = 2;
                                break;
                            case Models.AudioSelectionType.NotContains:
                                condition_ComboBox.SelectedIndex = 3;
                                break;
                            default:
                                condition_ComboBox.SelectedIndex = -1;
                                break;
                        }

                        switch (CurrentCombination.information.audioGroup.selectionType)
                        {
                            case Models.AudioSelectionType.Equal:
                                condition2_ComboBox.SelectedIndex = 0;
                                break;
                            case Models.AudioSelectionType.NotEqual:
                                condition2_ComboBox.SelectedIndex = 1;
                                break;
                            case Models.AudioSelectionType.Contains:
                                condition2_ComboBox.SelectedIndex = 2;
                                break;
                            case Models.AudioSelectionType.NotContains:
                                condition2_ComboBox.SelectedIndex = 3;
                                break;
                            default:
                                condition2_ComboBox.SelectedIndex = -1;
                                break;
                        }
                    }
                    else
                    {

                    }
                }
                else
                {
                    if (CurrentCombination.time.minPercent > 0.98)
                    {
                        this.byFill.IsChecked = true;
                       
                        this.configAudioInfo.IsChecked = false;
                       
                    }
                    else
                    {
                        this.byTime.IsChecked = true;
                        this.timeRange_ComboBox.SelectionChanged -= this.timeRange_ComboBox_SelectionChanged;
                        this.timeParam_ComboBox.SelectionChanged -= this.timeParam_ComboBox_SelectionChanged;
                        this.byTime_Checked(this, new RoutedEventArgs());

                        if (CurrentCombination.combinations != null && CurrentCombination.combinations.Count > 0)
                        {
                            this.configAudioInfo.IsChecked = false;
                        }
                        else if (CurrentCombination.information != null)
                        {
                            this.configAudioInfo.IsChecked = true;

                            switch (CurrentCombination.information.audioHz.selectionType)
                            {
                                case Models.AudioSelectionType.Equal:
                                    condition3_ComboBox.SelectedIndex = 0;
                                    break;
                                case Models.AudioSelectionType.NotEqual:
                                    condition3_ComboBox.SelectedIndex = 1;
                                    break;
                                case Models.AudioSelectionType.Contains:
                                    condition3_ComboBox.SelectedIndex = 2;
                                    break;
                                case Models.AudioSelectionType.NotContains:
                                    condition3_ComboBox.SelectedIndex = 3;
                                    break;
                                default:
                                    condition3_ComboBox.SelectedIndex = -1;
                                    break;
                            }

                            switch (CurrentCombination.information.audioType.selectionType)
                            {
                                case Models.AudioSelectionType.Equal:
                                    condition_ComboBox.SelectedIndex = 0;
                                    break;
                                case Models.AudioSelectionType.NotEqual:
                                    condition_ComboBox.SelectedIndex = 1;
                                    break;
                                case Models.AudioSelectionType.Contains:
                                    condition_ComboBox.SelectedIndex = 2;
                                    break;
                                case Models.AudioSelectionType.NotContains:
                                    condition_ComboBox.SelectedIndex = 3;
                                    break;
                                default:
                                    condition_ComboBox.SelectedIndex = -1;
                                    break;
                            }

                            switch (CurrentCombination.information.audioGroup.selectionType)
                            {
                                case Models.AudioSelectionType.Equal:
                                    condition2_ComboBox.SelectedIndex = 0;
                                    break;
                                case Models.AudioSelectionType.NotEqual:
                                    condition2_ComboBox.SelectedIndex = 1;
                                    break;
                                case Models.AudioSelectionType.Contains:
                                    condition2_ComboBox.SelectedIndex = 2;
                                    break;
                                case Models.AudioSelectionType.NotContains:
                                    condition2_ComboBox.SelectedIndex = 3;
                                    break;
                                default:
                                    condition2_ComboBox.SelectedIndex = -1;
                                    break;
                            }
                        }
                        else
                        {

                        }
                    }
                }
            }

        }

        private void ResetConfigAudio()
        {
            condition_ComboBox.SelectedIndex = -1;
            condition2_ComboBox.SelectedIndex = -1;
            condition3_ComboBox.SelectedIndex = -1;
            audioHz_ComboBox.SelectedIndex = -1;
            audioType_ComboBox.SelectedIndex = -1;
            audioGroup_ComboBox.SelectedIndex = -1;
        }

        private void treeView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
           

        }
        int index = -1;
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            this.byCount.IsEnabled= true;
            this.byTime.IsEnabled= true;
            this.byFill.IsEnabled= true;


           

            NotifyAudioCombination temp = new NotifyAudioCombination() {  };
         
            NotifyAudioCombination selectedItem = treeView.SelectedItem as NotifyAudioCombination;

            if (selectedItem == null)
            {
                System.Windows.MessageBox.Show("您还没有选择父节点！");
                return;
            }

            if (selectedItem.combinations == null)
            {
                if (selectedItem.information != null)
                {
                    selectedItem.information = null;
                }
                selectedItem.combinations = new ObservableCollection<NotifyAudioCombination>() { temp };
                index = 1;
                temp.name = selectedItem.name +"-"+ index;
            }
            else
            {
                if (selectedItem.information != null)
                {
                    selectedItem.information = null;
                }
                index++;
                selectedItem.combinations.Add(temp);
                temp.name = selectedItem.name + "-" + index;

            }           
            CurrentCombination = temp;
            this.configAudioInfo.IsChecked = false;
        }


        private void SetSelect(TreeViewItem tvi, AudioCombination data)  //这里的Model是你的treeview对应的模型
        {
            if (tvi.Items.Count > 0)
            {
                foreach (var item in tvi.Items)
                {
                    tvi.UpdateLayout(); //一定要加这句，否则下一句获得的tviChild 会为null
                    var tviChild = tvi.ItemContainerGenerator.ContainerFromItem(item);
                    if (tviChild == null)
                        continue;
                    var model = (AudioCombination)item;
                    if (data.name == model.name)  //使用模型中的一个属性数据进行匹配，该节点是否为选中
                    {
                        ((TreeViewItem)tviChild).IsSelected = true;
                        return;
                    }
                    else
                    {
                        SetSelect((TreeViewItem)tviChild, data);
                    }
                }
            }
        }

        // 将子方案从父方案中删除
        private void NewTreeRemoveChildren(NotifyAudioCombination parent, NotifyAudioCombination children)
        {
            foreach (var item in parent.combinations)
            {
                if (item.combinations != null)
                {
                    NewTreeRemoveChildren(item, children);
                }
                if (item == children)
                {
                    parent.combinations.Remove(item);
                    break;
                }

            }
            // parent.combinations.Add(children);
        }

        // 将子方案从父方案中删除
        private void TreeRemoveChildren(AudioCombination parent, AudioCombination children)
        {
            foreach (var item in parent.combinations)
            {
                if (item.combinations!=null)
                {
                    TreeRemoveChildren(item, children);
                }
                if (item.name == children.name)
                {
                    parent.combinations.Remove(item);
                    break;
                }

            }
           // parent.combinations.Add(children);
        }
        // 将子方案添加到父方案中
        private void TreeAddChidren(AudioCombination parent, AudioCombination children)
        {
            if (parent.combinations == null)
            {
                parent.combinations = new List<AudioCombination>();
            }            
            parent.combinations.Add(children);
        }

        // 刷新TreeView并返回Json格式的字符串结果
        private  string  ShowAndReturnJsonScheme()
        {
            string audioScheme = JsonConvert.SerializeObject(_audioCombination);
            JObject jsonObject = JObject.Parse(audioScheme);

            foreach (JProperty property in jsonObject.Descendants().OfType<JProperty>().ToList())
            {
                if (property.Value.Type == JTokenType.Null ||
                    (property.Value.Type == JTokenType.Integer && (int)property.Value == 0) ||
                    (property.Value.Type == JTokenType.Float && (double)property.Value == 0.0) ||
                    (property.Value.Type == JTokenType.String && string.IsNullOrEmpty((string)property.Value)) ||
                    (property.Value.Type == JTokenType.Object && !property.Value.HasValues))
                {
                    property.Remove();
                }
            }

            string filteredJsonString = jsonObject.ToString(Formatting.Indented);
            string formattedJsonString = JsonConvert.SerializeObject(jsonObject, Formatting.Indented);          

            // 刷新展示树
          //  treeView.ItemsSource = new List<SchemeTree> { _rootSchemeTree };

            return formattedJsonString;
        }


        private void configAudioInfo_Checked(object sender, RoutedEventArgs e)
        {
            if (IsLoaded)
            {
                if (configAudioInfo.IsChecked == true)
                {
                    //  configAudioBorder.Visibility = Visibility.Visible;

                    if (CurrentCombination.combinations != null && CurrentCombination.combinations.Count > 0)
                    {
                        this.configAudioInfo.IsChecked = false;
                    }
                    else
                    {
                        if (CurrentCombination.information==null)
                        {
                            CurrentCombination.information= new NotifyAudioInformation() { audioType = new Models.AudioSelectionCondition(),audioGroup= new Models.AudioSelectionCondition(),audioHz= new Models.AudioSelectionCondition()};
                            ResetConfigAudio();
                        }
                        else
                        {

                        }
                    }
                }
                else
                {
                    if (CurrentCombination.information != null)
                    {
                       
                        CurrentCombination.information = null;
                    }
                    else
                    {
                        
                    }

                    // configAudioBorder.Visibility = Visibility.Hidden;
                }
            }
          
        }

      

        private void byTime_Unchecked(object sender, RoutedEventArgs e)
        {

        }

        private void byTime_Checked(object sender, RoutedEventArgs e)
        {
            // Checked = "byTime_Checked" Unchecked = "byTime_Unchecked"

            this.timeRange_ComboBox.SelectionChanged -= this.timeRange_ComboBox_SelectionChanged;
            this.timeParam_ComboBox.SelectionChanged -= this.timeParam_ComboBox_SelectionChanged;

            if (byTime.IsChecked == true)
            {
                //left side 
                this.borderTime.Visibility = Visibility.Visible;
                
                this.timeRandomBorder.Visibility = Visibility.Hidden;
                this.timeAssignedBorder.Visibility = Visibility.Hidden;
                this.borderCount.Visibility = Visibility.Hidden;
                this.timeLinearBorder.Visibility = Visibility.Hidden;
                this.timeLinearPropBorder.Visibility = Visibility.Hidden;

                if (CurrentCombination.time == null)
                {
                    CurrentCombination.time = new HC.Standard.UniversalAudioScheme.TimeConfiguration();
                }
                else
                {
                    if (CurrentCombination.time.minPercent > 0.01 && CurrentCombination.time.minPercent < 1.0)
                    {
                        //按照百分比指定 线性比例时间  （0.33--0.67）（最小时间比例和最大时间比例；还有最小总时长 、最大总时长）
                        //随机时间 比例
                        if (CurrentCombination.time.maxPercent > 0.01)
                        {
                            // 线性比例时间
                            if (CurrentCombination.time.minDuration > 0.01)
                            {
                                this.timeLinearPropBorder.Visibility = Visibility.Visible;
                                this.timeRange_ComboBox.SelectedIndex = 2;  //线性时间
                                timeParam_ComboBox.SelectedIndex = 1;       //%

                                this.minLinerPropTotalSecondTxt.IsEnabled = true;
                                this.maxLinerPropTotalSecondTxt.IsEnabled = true;
                                this.maxLinerSecondPropTxt.IsEnabled = true;

                            }
                            //随机时间
                            else
                            {

                                this.timeLinearPropBorder.Visibility = Visibility.Visible;
                                this.timeRange_ComboBox.SelectedIndex = 1;  //随机时间
                                timeParam_ComboBox.SelectedIndex = 1;       //%

                                this.maxLinerSecondPropTxt.IsEnabled = true;

                                this.minLinerPropTotalSecondTxt.IsEnabled = false;
                                this.maxLinerPropTotalSecondTxt.IsEnabled = false;


                            }


                        }
                        //按照百分比指定 （线性）时间
                        else
                        {
                            this.timeLinearPropBorder.Visibility = Visibility.Visible;
                            this.timeRange_ComboBox.SelectedIndex = 0;  //指定时间
                            timeParam_ComboBox.SelectedIndex = 1;       //%

                            this.minLinerPropTotalSecondTxt.IsEnabled = false;
                            this.maxLinerPropTotalSecondTxt.IsEnabled = false;
                            this.maxLinerSecondPropTxt.IsEnabled = false;
                        }
                    }

                    else 
                    {
                        if (CurrentCombination.time.minSeconds > 0 && CurrentCombination.time.maxSeconds > 0)
                        {
                            //线性时间  实际时间
                            if (CurrentCombination.time.minDuration > 0)
                            {
                                this.timeLinearBorder.Visibility = Visibility.Visible;

                                this.timeRange_ComboBox.SelectedIndex = 2;  //线性时间
                                timeParam_ComboBox.SelectedIndex = 0;       //实际时间

                                this.maxLinerSecondPropTxt.IsEnabled = true;
                                this.minLinerPropTotalSecondTxt.IsEnabled = true;
                                this.maxLinerPropTotalSecondTxt.IsEnabled = true;

                            }
                            //随机时间  实际时间
                            else
                            {

                                this.timeRandomBorder.Visibility = Visibility.Visible;

                                this.timeRange_ComboBox.SelectedIndex = 1;  //随机时间
                                timeParam_ComboBox.SelectedIndex = 0;       //实际时间

                                this.minSecondTxt.IsEnabled = true;
                                this.maxSecondTxt.IsEnabled = true;
                              

                            }
                        }
                        //指定时间 实际时间
                        else 
                        {
                            if (CurrentCombination.time.minPercent > 0.98)
                            {

                            }
                            else
                            {
                                this.timeAssignedBorder.Visibility = Visibility.Visible;

                                this.timeRange_ComboBox.SelectedIndex = 0;  //指定时间
                                timeParam_ComboBox.SelectedIndex = 0;       //实际时间
                            }
                           


                        }
                    }
                }


               

                string timeParamString = string.Empty;
                string timeRangeString = string.Empty;
                if (timeParam_ComboBox.SelectedItem != null)
                {
                    timeParamString = (timeParam_ComboBox.SelectedItem as ComboBoxItem).Content.ToString();
                }

                if (timeRange_ComboBox.SelectedItem != null)
                {
                    timeRangeString = (timeRange_ComboBox.SelectedItem as ComboBoxItem).Content.ToString();
                }



              


                //   string timeParamString = (timeParam_ComboBox.SelectedItem as ComboBoxItem).Content.ToString();

                //    string timeRangeString = (timeRange_ComboBox.SelectedItem as ComboBoxItem).Content.ToString();

                if (timeParamString=="百分比")
                {
                    // this.timeLinearPropBorder.Visibility = Visibility.Visible;

                    if (timeRangeString == "线性时间")
                    {
                        this.timeRandomBorder.Visibility = Visibility.Hidden;
                        this.timeAssignedBorder.Visibility = Visibility.Hidden;
                        this.timeLinearBorder.Visibility = Visibility.Hidden;

                        this.timeLinearPropBorder.Visibility = Visibility.Visible;
                        this.maxLinerSecondPropTxt.IsEnabled = true;

                        if (CurrentCombination.time == null)
                        {
                            CurrentCombination.time = new HC.Standard.UniversalAudioScheme.TimeConfiguration();
                        }
                    }
                    else if (timeRangeString == "随机时间")
                    {
                        this.timeRandomBorder.Visibility = Visibility.Hidden;                       
                        this.timeLinearBorder.Visibility = Visibility.Hidden;
                        this.timeAssignedBorder.Visibility = Visibility.Hidden;

                        this.timeLinearPropBorder.Visibility = Visibility.Visible;                     

                        this.maxLinerSecondPropTxt.IsEnabled = true;

                        this.minLinerPropTotalSecondTxt.IsEnabled = false;
                        this.maxLinerPropTotalSecondTxt.IsEnabled = false;
                    }
                    else if (timeRangeString == "指定时间")
                    {
                        this.timeRandomBorder.Visibility = Visibility.Hidden;                   

                        this.timeAssignedBorder.Visibility = Visibility.Hidden;
                        this.timeLinearBorder.Visibility = Visibility.Hidden;
                        this.timeLinearPropBorder.Visibility = Visibility.Visible;
                       

                        this.minLinerPropTotalSecondTxt.IsEnabled = false;
                        this.maxLinerPropTotalSecondTxt.IsEnabled = false;
                        this.maxLinerSecondPropTxt.IsEnabled = false;

                    }




                }
                else
                {
                    if (timeRangeString == "指定时间" && timeParamString == "实际时间")
                    {
                        this.timeLinearPropBorder.Visibility = Visibility.Hidden;
                        this.timeLinearBorder.Visibility = Visibility.Hidden;
                        this.timeRandomBorder.Visibility = Visibility.Hidden;
                        this.timeAssignedBorder.Visibility = Visibility.Visible;

                        if (CurrentCombination.time==null)
                        {
                            CurrentCombination.time = new HC.Standard.UniversalAudioScheme.TimeConfiguration();
                        }
                    }
                    if (timeRangeString == "随机时间" && timeParamString == "实际时间")
                    {
                        this.timeLinearPropBorder.Visibility = Visibility.Hidden;
                        this.timeLinearBorder.Visibility = Visibility.Hidden;
                     
                        this.timeAssignedBorder.Visibility = Visibility.Hidden;
                        this.timeRandomBorder.Visibility = Visibility.Visible;
                        this.minSecondTxt.IsEnabled = true;
                        this.maxSecondTxt.IsEnabled = true;

                        if (CurrentCombination.time == null)
                        {
                            CurrentCombination.time = new HC.Standard.UniversalAudioScheme.TimeConfiguration();
                        }
                    }
                    if (timeRangeString == "线性时间" && timeParamString == "实际时间")
                    {
                        this.timeLinearPropBorder.Visibility = Visibility.Hidden;
                        this.timeAssignedBorder.Visibility = Visibility.Hidden;
                        this.timeRandomBorder.Visibility = Visibility.Hidden;

                        this.timeLinearBorder.Visibility = Visibility.Visible;
                        if (CurrentCombination.time == null)
                        {
                            CurrentCombination.time = new HC.Standard.UniversalAudioScheme.TimeConfiguration();
                        }
                    }

                    if (timeRangeString == "线性时间" && timeParamString == "百分比")
                    {
                        this.timeRandomBorder.Visibility = Visibility.Hidden;
                        this.timeAssignedBorder.Visibility = Visibility.Hidden;                        
                        this.timeLinearBorder.Visibility = Visibility.Hidden;
                        this.timeLinearPropBorder.Visibility = Visibility.Visible;
                        
                        this.maxLinerSecondPropTxt.IsEnabled = true;

                        if (CurrentCombination.time == null)
                        {
                            CurrentCombination.time = new HC.Standard.UniversalAudioScheme.TimeConfiguration();
                        }
                    }

                }

                
            }
            else if (byCount.IsChecked == true)
            {
                this.borderTime.Visibility = Visibility.Hidden;
                this.timeRandomBorder.Visibility = Visibility.Hidden;
                this.timeAssignedBorder.Visibility = Visibility.Hidden;
                this.borderCount.Visibility = Visibility.Visible;    
                this.timeLinearBorder.Visibility = Visibility.Hidden;
                this.timeLinearPropBorder.Visibility = Visibility.Hidden;

                if (CurrentCombination.time != null&&CurrentCombination.time.minPercent < 1.0)
                {
                  CurrentCombination.time = null;
                }
            }
            else if (byFill.IsChecked == true)
            {
                this.borderTime.Visibility = Visibility.Hidden;
                this.timeRandomBorder.Visibility = Visibility.Hidden;
                this.timeAssignedBorder.Visibility = Visibility.Hidden;
                this.borderCount.Visibility = Visibility.Hidden;
                this.timeLinearBorder.Visibility = Visibility.Hidden;
                this.timeLinearPropBorder.Visibility = Visibility.Hidden;

                if (CurrentCombination.time!= null && CurrentCombination.time.minPercent < 1.0) 
                {
                    CurrentCombination.time = null;
                }
                
            }


            this.timeRange_ComboBox.SelectionChanged += this.timeRange_ComboBox_SelectionChanged;
            this.timeParam_ComboBox.SelectionChanged += this.timeParam_ComboBox_SelectionChanged;
        }

        private void btnSave_Click(object sender, RoutedEventArgs e)
        {

            if (SolutionIsComplete(_AudioCombination))
            {
            }
            else 
            {
                System.Windows.MessageBox.Show("方案不完整");
                return;
            }


          string schemeString =  ShowAndReturnJsonScheme();


            AudioCombination combination = JsonConvert.DeserializeObject<AudioCombination>(schemeString);
            string schemeId = combination.id.ToString();
            // 获取桌面路径
            //string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            string path = System.IO.Path.Combine(MainWindow.selectedPath, schemeId + ".txt");
            File.WriteAllText(path, schemeString);
            System.Windows.MessageBox.Show("文本已保存到原有目录下");

        }

        bool AllComplete = true;
        private bool SolutionIsComplete(NotifyAudioCombination combinationToCheck)
        {
             AllComplete = true;
         
                foreach (var item in combinationToCheck.combinations)
               {
                            if (item.combinations != null && item.information != null)
                            {
                                System.Windows.MessageBox.Show("不能同时存在子方案和音频信息");
                                AllComplete = false;                               
                                // NewTreeRemoveChildren(item, children);                                
                            }
                            else
                            {

                                if (item.time!=null)
                                   {
                                        if (item.time.minSeconds * item.time.maxSeconds > 0)
                                        {
                                            if (item.time.minSeconds > item.time.maxSeconds )
                                            {
                                                System.Windows.MessageBox.Show(item.name + "方案下:时间设置不正确");
                                                AllComplete = false;
                                            }
                                         }
                                        if (item.time.minDuration * item.time.maxDuration > 0)
                                         {
                                            if (item.time.minDuration > item.time.maxDuration)
                                            {
                                                System.Windows.MessageBox.Show(item.name + "方案下:时间设置不正确");
                                                AllComplete = false;
                                            }
                                        }

                                        if (item.time.minPercent * item.time.maxPercent > 0)
                                        {
                                            if (item.time.minPercent > item.time.maxPercent)
                                            {
                                                System.Windows.MessageBox.Show(item.name + "方案下:时间设置不正确");
                                                AllComplete = false;
                                            }
                        }

                                         }
                                    
                                if (item.combinations == null)
                                {
                                    if (item.information == null)
                                    {
                                        System.Windows.MessageBox.Show(item.name + "方案下:没有设置音频信息");
                                        AllComplete = false;
                                     }
                                    else
                                    {
                                     
                                       // return true;
                                    }

                                }
                                else 
                                {
                                        SolutionIsComplete(item);
                                }
                       
                            }               

                }

            if (AllComplete)
            {
                return true;
            }
            else
            {
                return false;
            }

           
            
        }

        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {

            NewTreeRemoveChildren(_AudioCombination, CurrentCombination);



           if (_selectAudioCombination != null)
                {                

             //   TreeRemoveChildren(_audioCombination, _selectAudioCombination);
              //  treeView.ItemsSource = new List<AudioCombination>() { _audioCombination };
            }

           
        }

        private void timeParam_ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //if (timeParam_ComboBox.SelectedIndex==1)
            //{
            //    timeLinearPropBorder.Visibility = Visibility.Visible;
            //}
            //else
            //{
            //    timeLinearPropBorder.Visibility = Visibility.Hidden;
            //}

            string timeParamString = string.Empty;
            string timeRangeString = string.Empty;
            if (timeParam_ComboBox.SelectedItem != null)
            {
                timeParamString = (timeParam_ComboBox.SelectedItem as ComboBoxItem).Content.ToString();
            }

            if (timeRange_ComboBox.SelectedItem != null)
            {
                timeRangeString = (timeRange_ComboBox.SelectedItem as ComboBoxItem).Content.ToString();
            }        


            if (timeParamString == "百分比")
            {
                if (timeRangeString == "线性时间")
                {


                    if (CurrentCombination.time.minPercent > 0.01 && CurrentCombination.time.minPercent < 1.0)
                    {
                        if (CurrentCombination.time.maxPercent > 0.01 && CurrentCombination.time.minDuration > 1)
                        {

                        }
                        else
                        {
                            //重置
                            CurrentCombination.time = new HC.Standard.UniversalAudioScheme.TimeConfiguration();
                        }
                    }
                    else
                    {
                        //重置
                        CurrentCombination.time = new HC.Standard.UniversalAudioScheme.TimeConfiguration();
                    }

                    this.timeRandomBorder.Visibility = Visibility.Hidden;
                    this.timeAssignedBorder.Visibility = Visibility.Hidden;
                    this.timeLinearBorder.Visibility = Visibility.Hidden;
                    this.timeLinearPropBorder.Visibility = Visibility.Visible;



                    this.minLinerPropTotalSecondTxt.IsEnabled = true;
                    this.maxLinerPropTotalSecondTxt.IsEnabled = true;
                    this.maxLinerSecondPropTxt.IsEnabled = true;


                }
                else if (timeRangeString == "随机时间")
                {

                    if (CurrentCombination.time.minPercent > 0.01 && CurrentCombination.time.minPercent < 1.0)
                    {
                        if (CurrentCombination.time.maxPercent > 0.01)
                        {

                        }
                        else
                        {
                            //重置
                            CurrentCombination.time = new HC.Standard.UniversalAudioScheme.TimeConfiguration();
                        }
                    }
                    else
                    {
                        //重置
                        CurrentCombination.time = new HC.Standard.UniversalAudioScheme.TimeConfiguration();
                    }

                    this.timeRandomBorder.Visibility = Visibility.Hidden;
                    this.timeAssignedBorder.Visibility = Visibility.Hidden;
                    this.timeLinearBorder.Visibility = Visibility.Hidden;
                    this.timeLinearPropBorder.Visibility = Visibility.Visible;



                    this.maxLinerSecondPropTxt.IsEnabled = true;

                    this.minLinerPropTotalSecondTxt.IsEnabled = false;
                    this.maxLinerPropTotalSecondTxt.IsEnabled = false;
                }
                else if (timeRangeString == "指定时间")
                {

                    if (CurrentCombination.time.minPercent > 0.01 && CurrentCombination.time.minPercent < 1.0)
                    {
                        if (CurrentCombination.time.maxPercent < 0.01)
                        {

                        }
                        else
                        {
                            //重置
                            CurrentCombination.time = new HC.Standard.UniversalAudioScheme.TimeConfiguration();
                        }
                    }
                    else
                    {
                        if (CurrentCombination.time.minPercent < 0.001)
                        {
                            //重置
                            CurrentCombination.time = new HC.Standard.UniversalAudioScheme.TimeConfiguration();
                        }

                    }

                    this.timeRandomBorder.Visibility = Visibility.Hidden;
                    this.timeAssignedBorder.Visibility = Visibility.Hidden;
                    this.timeLinearBorder.Visibility = Visibility.Hidden;
                    this.timeLinearPropBorder.Visibility = Visibility.Visible;


                    this.minLinerPropTotalSecondTxt.IsEnabled = false;
                    this.maxLinerPropTotalSecondTxt.IsEnabled = false;
                    this.maxLinerSecondPropTxt.IsEnabled = false;

                }


            }
            else
            {
                this.timeLinearPropBorder.Visibility = Visibility.Hidden;

                if (timeRangeString == "指定时间" && timeParamString == "实际时间")
                {
                    if (CurrentCombination.time.minSeconds > 0 && CurrentCombination.time.maxSeconds < 0.001)
                    {
                        //old goes here    
                    }
                    else
                    {
                        //重置
                        CurrentCombination.time = new HC.Standard.UniversalAudioScheme.TimeConfiguration();
                    }


                    this.timeLinearBorder.Visibility = Visibility.Hidden;
                    this.timeLinearPropBorder.Visibility = Visibility.Hidden;
                    this.timeRandomBorder.Visibility = Visibility.Hidden;

                    this.timeAssignedBorder.Visibility = Visibility.Visible;


                }
                if (timeRangeString == "随机时间" && timeParamString == "实际时间")
                {

                    if (CurrentCombination.time.minSeconds > 0 && CurrentCombination.time.maxSeconds > 0)
                    {

                        if (CurrentCombination.time.minDuration > 0) // 原来是 线性时间  实际时间
                        {
                            //重置
                            CurrentCombination.time = new HC.Standard.UniversalAudioScheme.TimeConfiguration();
                        }
                        else
                        {

                            //old  goes  here 

                        }
                    }

                    else
                    {
                        //重置
                        CurrentCombination.time = new HC.Standard.UniversalAudioScheme.TimeConfiguration();
                    }

                    this.timeLinearBorder.Visibility = Visibility.Hidden;
                    this.timeLinearPropBorder.Visibility = Visibility.Hidden;
                    this.timeAssignedBorder.Visibility = Visibility.Hidden;
                    this.timeRandomBorder.Visibility = Visibility.Visible;
                    this.minSecondTxt.IsEnabled = true;
                    this.maxSecondTxt.IsEnabled = true;



                }
                if (timeRangeString == "线性时间" && timeParamString == "实际时间")
                {
                    if (CurrentCombination.time.minSeconds > 0 && CurrentCombination.time.maxSeconds > 0)
                    {
                        if (CurrentCombination.time.minDuration > 0)
                        {
                            // old goes here 
                        }
                        else
                        {
                            //重置
                            CurrentCombination.time = new HC.Standard.UniversalAudioScheme.TimeConfiguration();
                        }
                    }
                    else
                    {
                        //重置
                        CurrentCombination.time = new HC.Standard.UniversalAudioScheme.TimeConfiguration();
                    }
                    this.timeLinearPropBorder.Visibility = Visibility.Hidden;
                    this.timeAssignedBorder.Visibility = Visibility.Hidden;
                    this.timeRandomBorder.Visibility = Visibility.Hidden;
                    this.timeLinearBorder.Visibility = Visibility.Visible;
                }

            }

        }

        private void audioType_ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (_isLoaded)
            {
                if (this.audioType_ComboBox.SelectedItem==null)
                {
                    return;
                }
            IEnumerable<string> distinctNames = _allAudio.Where(a => a.audio_type == this.audioType_ComboBox.SelectedItem.ToString()).Select(obj => obj.audio_group).Distinct();
            audioGroupColletion.Clear();
            foreach (var item in distinctNames)
            {
                audioGroupColletion.Add(item);
            }
            CurrentCombination.information.audioType.name = this.audioType_ComboBox.SelectedItem.ToString();
            }
        }

        private void audioGroup_ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (this.audioType_ComboBox.SelectedItem==null) 
            {
                return;
            }
            if (this.audioGroup_ComboBox.SelectedItem == null)
            {
                return;
            }

            IEnumerable<int> distinctNames = _allAudio.Where(a => a.audio_type == this.audioType_ComboBox.SelectedItem.ToString()&&a.audio_group==this.audioGroup_ComboBox.SelectedItem.ToString()).Select(obj => obj.audio_hz).Distinct();

            audioHzColletion.Clear();
            foreach (var item in distinctNames)
            {
                audioHzColletion.Add(item);
            }

            //shouldn't appear here 

            if (CurrentCombination.information == null)
            {
                CurrentCombination.information = new NotifyAudioInformation() { audioGroup =new Models.AudioSelectionCondition(),audioHz=new Models.AudioSelectionCondition(),audioType=new Models.AudioSelectionCondition() };
            }

            CurrentCombination.information.audioGroup.name = this.audioGroup_ComboBox.SelectedItem.ToString();
        }

        private void condition_ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (_isLoaded)
            {
                if (condition_ComboBox.SelectedItem==null)
                {
                    return;
                }
                string aStr = (condition_ComboBox.SelectedItem as ComboBoxItem).Content.ToString();
                if (aStr == "等于")
                {
                    CurrentCombination.information.audioType.selectionType = InnerAudioScheme.Models.AudioSelectionType.Equal;
                }
                else if (aStr == "不等于")
                {
                    CurrentCombination.information.audioType.selectionType = InnerAudioScheme.Models.AudioSelectionType.NotEqual;
                }
                else if (aStr == "包含")
                {
                    CurrentCombination.information.audioType.selectionType = InnerAudioScheme.Models.AudioSelectionType.Contains;
                }
                else
                {
                    CurrentCombination.information.audioType.selectionType = InnerAudioScheme.Models.AudioSelectionType.NotContains;
                }
            }

           
        }

        private void condition2_ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (_isLoaded)
            {
                if (condition2_ComboBox.SelectedItem==null)
                {
                    return;
                }
                string aStr = (condition2_ComboBox.SelectedItem as ComboBoxItem).Content.ToString();
               
                if (aStr == "等于")
                {
                    CurrentCombination.information.audioGroup.selectionType = InnerAudioScheme.Models.AudioSelectionType.Equal;
                }
                else if (aStr == "不等于")
                {
                    CurrentCombination.information.audioGroup.selectionType = InnerAudioScheme.Models.AudioSelectionType.NotEqual;
                }
                else if (aStr == "包含")
                {
                    CurrentCombination.information.audioGroup.selectionType = InnerAudioScheme.Models.AudioSelectionType.Contains;
                }
                else
                {
                    CurrentCombination.information.audioGroup.selectionType = InnerAudioScheme.Models.AudioSelectionType.NotContains;
                }
            }
        }

        private void condition3_ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (_isLoaded)
            {
                if (condition3_ComboBox.SelectedItem == null)
                {
                    return;
                }
                string aStr = (condition3_ComboBox.SelectedItem as ComboBoxItem).Content.ToString();
                if (aStr == "等于")
                {
                    CurrentCombination.information.audioHz.selectionType = InnerAudioScheme.Models.AudioSelectionType.Equal;
                }
                else if (aStr == "不等于")
                {
                    CurrentCombination.information.audioHz.selectionType = InnerAudioScheme.Models.AudioSelectionType.NotEqual;
                }
                else if (aStr == "包含")
                {
                    CurrentCombination.information.audioHz.selectionType = InnerAudioScheme.Models.AudioSelectionType.Contains;
                }
                else
                {
                    CurrentCombination.information.audioHz.selectionType = InnerAudioScheme.Models.AudioSelectionType.NotContains;
                }
            }
        }

        private void audioHz_ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (_isLoaded)
            {
                if (CurrentCombination.information!=null && CurrentCombination.information.audioHz!=null)
                {
                    string timeParamString = string.Empty;
                
                    if (this.audioHz_ComboBox.SelectedItem != null)
                    {
                        timeParamString = this.audioHz_ComboBox.SelectedItem.ToString(); 

                       // CurrentCombination.information.audioGroup.name = this.audioHz_ComboBox.SelectedItem.ToString();
                    }                

                    CurrentCombination.information.audioHz.selectionType = 0;
                    CurrentCombination.information.audioHz.name = timeParamString;
                }
            }
            //CurrentCombination.information.audioType.name = this.audioType_ComboBox.SelectedItem.ToString();
        }

        private void timeRange_ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            string timeParamString = string.Empty;
            string timeRangeString = string.Empty;
            if (timeParam_ComboBox.SelectedItem != null )
            {
                timeParamString = (timeParam_ComboBox.SelectedItem as ComboBoxItem).Content.ToString();
            }

            if (timeRange_ComboBox.SelectedItem != null)
            {
                timeRangeString = (timeRange_ComboBox.SelectedItem as ComboBoxItem).Content.ToString();
            }







            //    string timeParamString = (timeParam_ComboBox.SelectedItem as ComboBoxItem).Content.ToString();

            //   string timeRangeString = (timeRange_ComboBox.SelectedItem as ComboBoxItem).Content.ToString();




            if (timeParamString == "百分比")
            {
                if (timeRangeString == "线性时间")
                {
                   

                    if (CurrentCombination.time.minPercent > 0.01 && CurrentCombination.time.minPercent < 1.0)
                    {
                        if (CurrentCombination.time.maxPercent > 0.01 && CurrentCombination.time.minDuration > 1)
                        {
                           
                        }
                        else 
                        {
                            //重置
                            CurrentCombination.time = new HC.Standard.UniversalAudioScheme.TimeConfiguration();
                        }
                    }
                    else
                    {
                        //重置
                        CurrentCombination.time = new HC.Standard.UniversalAudioScheme.TimeConfiguration();
                    }


                    this.timeRandomBorder.Visibility = Visibility.Hidden;
                    this.timeAssignedBorder.Visibility = Visibility.Hidden;
                    this.timeLinearPropBorder.Visibility = Visibility.Hidden;
                    this.timeLinearPropBorder.Visibility = Visibility.Visible;

                  

                    this.minLinerPropTotalSecondTxt.IsEnabled = true;
                    this.maxLinerPropTotalSecondTxt.IsEnabled = true;
                    this.maxLinerSecondPropTxt.IsEnabled = true;


                }
                else if (timeRangeString == "随机时间")
                {

                    if (CurrentCombination.time.minPercent > 0.01 && CurrentCombination.time.minPercent < 1.0)
                    {
                        if (CurrentCombination.time.maxPercent > 0.01)
                        {
                            
                        }
                        else 
                        {
                            //重置
                            CurrentCombination.time = new HC.Standard.UniversalAudioScheme.TimeConfiguration();
                        }
                    }

                    else
                    {
                        if (CurrentCombination.time.minPercent < 0.001)
                        {
                            //重置
                            CurrentCombination.time = new HC.Standard.UniversalAudioScheme.TimeConfiguration();
                        }

                    }

                    this.timeRandomBorder.Visibility = Visibility.Hidden;
                    this.timeAssignedBorder.Visibility = Visibility.Hidden;
                    this.timeLinearPropBorder.Visibility = Visibility.Hidden;
                    this.timeLinearPropBorder.Visibility = Visibility.Visible;

                   

                    this.maxLinerSecondPropTxt.IsEnabled = true;

                    this.minLinerPropTotalSecondTxt.IsEnabled = false;
                    this.maxLinerPropTotalSecondTxt.IsEnabled = false;
                }
                else if (timeRangeString == "指定时间")
                {

                    if (CurrentCombination.time.minPercent > 0.01 && CurrentCombination.time.minPercent < 1.0)
                    {
                        if (CurrentCombination.time.maxPercent < 0.01)
                        {
                            
                        }
                        else
                        {
                            //重置
                            CurrentCombination.time = new HC.Standard.UniversalAudioScheme.TimeConfiguration();
                        }
                    }
                   
                    this.timeRandomBorder.Visibility = Visibility.Hidden;
                    this.timeAssignedBorder.Visibility = Visibility.Hidden;
                    this.timeLinearPropBorder.Visibility = Visibility.Hidden;
                    this.timeLinearPropBorder.Visibility = Visibility.Visible;


                    this.minLinerPropTotalSecondTxt.IsEnabled = false;
                    this.maxLinerPropTotalSecondTxt.IsEnabled = false;
                    this.maxLinerSecondPropTxt.IsEnabled = false;

                }


            }
            else
            {
                this.timeLinearPropBorder.Visibility = Visibility.Hidden;

                if (timeRangeString == "指定时间" && timeParamString == "实际时间")
                {
                    if (CurrentCombination.time.minSeconds > 0 && CurrentCombination.time.maxSeconds < 0.001)
                    {
                        //old goes here    
                    }
                    else
                    {
                        //重置
                        CurrentCombination.time = new HC.Standard.UniversalAudioScheme.TimeConfiguration();
                    }

                 
                    this.timeLinearPropBorder.Visibility = Visibility.Hidden;
                    this.timeLinearBorder.Visibility = Visibility.Hidden;
                    this.timeRandomBorder.Visibility = Visibility.Hidden;

                    this.timeAssignedBorder.Visibility = Visibility.Visible;

                   
                }
                if (timeRangeString == "随机时间" && timeParamString == "实际时间")
                {

                    if (CurrentCombination.time.minSeconds > 0 && CurrentCombination.time.maxSeconds > 0)
                    {

                        if (CurrentCombination.time.minDuration > 0) // 原来是 线性时间  实际时间
                        {
                            //重置
                            CurrentCombination.time = new HC.Standard.UniversalAudioScheme.TimeConfiguration();
                        }
                        else
                        {

                            //old  goes  here 

                        }
                    }
                    else
                    {
                        //重置

                        CurrentCombination.time = new HC.Standard.UniversalAudioScheme.TimeConfiguration();
                    }
                    this.timeLinearPropBorder.Visibility = Visibility.Hidden;
                    this.timeLinearBorder.Visibility = Visibility.Hidden;
                    this.timeAssignedBorder.Visibility = Visibility.Hidden;
                    this.timeRandomBorder.Visibility = Visibility.Visible;
                    this.minSecondTxt.IsEnabled = true;
                    this.maxSecondTxt.IsEnabled = true;



                }
                if (timeRangeString == "线性时间" && timeParamString == "实际时间")
                {
                    if (CurrentCombination.time.minSeconds > 0 && CurrentCombination.time.maxSeconds > 0)
                    {
                        if (CurrentCombination.time.minDuration > 0)
                        {
                            // old goes here 
                        }
                        else
                        {
                            //重置
                            CurrentCombination.time = new HC.Standard.UniversalAudioScheme.TimeConfiguration();
                        }
                    }
                    else
                    {
                        //重置
                        CurrentCombination.time = new HC.Standard.UniversalAudioScheme.TimeConfiguration();
                    }
                    this.timeLinearPropBorder.Visibility = Visibility.Hidden;
                    this.timeAssignedBorder.Visibility = Visibility.Hidden;
                    this.timeRandomBorder.Visibility = Visibility.Hidden;
                    this.timeLinearBorder.Visibility = Visibility.Visible;
                }

            }

        }
    }
}
